<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="applicable-device" content="pc">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="keywords" content="">
		<meta name="description" content="">

		<link rel="icon" href="">
		<link rel="stylesheet" href="/static/index/css/reset.css">
        <link rel="stylesheet" href="/static/index/lib/bootstrap.css">

        <link rel="stylesheet" href="/static/index/css/common.css">
        <link rel="stylesheet" href="/static/index/css/home.css">
        	<link rel="stylesheet" href="/static/index/css/users.css">

		<script src="/static/index/lib/jquery-2.1.4.js"></script>
		<script src="/static/index/lib/bootstrap.min.js"></script>
        <script>
            var _hmt = _hmt || [];
            (function() {
              var hm = document.createElement("script");
              hm.src = "https://hm.baidu.com/hm.js?8b340ebdd740974de9d621b14ab09b43";
              var s = document.getElementsByTagName("script")[0]; 
              s.parentNode.insertBefore(hm, s);
            })();
        </script>
	</head>

	<body>
        {include file="public/push"}
		{include file="public/usersHeader"}

		<div class="widthFullScreen">
			<div class="wdSafe user_body clearfix">
				{include file="public/usersLeftNav"}
				<!-- left over -->
				<div class="pull-right right_wrap">
					<div class="nav_common border-top">
						<ol class="breadcrumb pull-left">
							<li>
								<a href="#">用户中心</a>
							</li>
							<li>
								<a href="#">我的账户</a>
							</li>
							<li class="active">修改密码</li>
						</ol>
					</div>

					<div class="comUser_wrap">
						<form class="form-horizontal">
							<div class="form-group">
								<label for="two" class="col-sm-2 control-label">
									<span class="colorRed">*</span>&nbsp;&nbsp;手机号码
								</label>
								<div class="col-sm-10">
									<input autocomplete='number' type="number" class="form-control ipt_styleSub" name="phone" placeholder="请输入手机号码" id="phoneNum" value="" />
								</div>
							</div>
							<div class="form-group">
								<label for="two" class="col-sm-2 control-label">
									<span class="colorRed">*</span>&nbsp;&nbsp;验证码
								</label>
								<div class="col-sm-10">
									<input type="text" class="form-control ipt_codeIpt pull-left" placeholder="请输入手机验证码" name="" id="codeNum" value="" />
									<input type="button" class="form-control sendCode pull-left" value="获取验证码" name="" value="" id="sendCode"/>
								</div>
							</div>
							<div class="form-group">
								<label for="two" class="col-sm-2 control-label">
									<span class="colorRed">*</span>&nbsp;&nbsp;新密码
								</label>
								<div class="col-sm-10">
									<input autocomplete='password' type="password" class="form-control ipt_styleSub" name="" id="password" placeholder="请输入新密码" value="" />
								</div>
							</div>
							<div class="form-group">
								<label for="two" class="col-sm-2 control-label">
									<span class="colorRed">*</span>&nbsp;&nbsp;确认新密码
								</label>
								<div class="col-sm-10">
									<input autocomplete='password' type="password" class="form-control ipt_styleSub" name="" id="repeatPassword" placeholder="请输入再次输入密码" value="" />
								</div>
							</div>
							<div class="form-group">
								<div class="col-sm-offset-2 col-sm-10">
									<div class="submitBtn" onclick="regin()">保存</div>
								</div>
							</div>
						</form>
					</div>

				</div>
				<!-- right over -->
			</div>
		</div>

		<div class="widthFullScreen heightGray"></div>

		{include file="public/footer"}

		<script src="/static/index/layer/layer.js"></script>

        <script type="text/javascript">
            var baseUrl = 'https://api.qikuai100.com/';
            var countdown = 60;
            $(function() {
                $('#sendCode').click(function() {
                    sendCode();
                });
                $('#reginBtn').click(function() {
                    regin();
                });
                
            });
            
            /**
             * 发送验证码
             * */
            function sendCode() {
                var phone = $("#phoneNum").val();
                var result = isPhoneNum();
                if(result){
                        $.ajax({
                        type: "POST",
                        url: baseUrl + "api/captcha/register",
                        data: {
                            "phone": phone
                        },
                        success: function(result) {
                            if(result.ret == 0){
                                settime($('#sendCode'));
                            }
                        }
                    });
                }
            }
            
            // 注册
            function regin(){
                var phone = $("#phoneNum").val(),
                    password1 = $("#password").val(),
                    passwordRepeat = $("#repeatPassword").val(),
                    codeNum = $("#codeNum").val();
                var result = isPhoneNum();
                
                if(!result){
                    return;
                }
                if($.trim(password1) == ""){
                    layer.msg("请输入密码");
                    return;
                }
                if($.trim(password1).length < 6){
                    layer.msg("请输入6位以上的密码");
                    return;
                }
                if($.trim(passwordRepeat) != $.trim(password1)){
                    layer.msg("两次输入密码不一致");
                    return;
                }
                if($.trim(codeNum) == ""){
                    layer.msg("请输入验证码");
                    return;
                }
                $.ajax({
                    type: "POST",
                    url: baseUrl + "api/auth/forgetpwd",
                    data: {
                        "phone": phone,
                        "password": password1,
                        "confirm_password": passwordRepeat,
                        "captcha": codeNum
                    },
                    success: function(result) {
                        if(result.ret == 0){
                            layer.msg("密码修改成功！");
                            setTimeout(function() {
                                window.location.href = '/user/login';
                            }, 1000);
                        }else{
                            layer.msg(result.res_info);
                        }
                    }
                });
            }
            
            // 倒计时
            function settime(obj) {
                if(countdown == 0) {
                    obj.removeAttr("disabled"); 
                    obj.val("获取验证码");
                    return;
                } else {
                    obj.attr("disabled", true);
                    obj.val("重新发送(" + countdown + ")");
                    countdown--;
                }
                setTimeout(function() {
                    settime(obj);
                }, 1000)
            }
            
            //校验手机号是否合法
            function isPhoneNum() {
                var phone_1 = $("#phoneNum").val();
                var myreg = /^1[34578]\d{9}$/;
                if(!myreg.test(phone_1)) {
                    layer.msg("请输入有效的手机号码");
                    return false;
                } else {
                    return true;
                }
            }
            
        </script>

	</body>

</html>